package controllers.validation.sensor;

import org.junit.Assert;
import org.junit.Test;

import controllers.validation.AbstractValidationTest;
import controllers.validation.jobs.NodeValidationJob;
import controllers.validation.jobs.SensorValidationJob;
import ch.bfh.abcm.rems.gateway.GateWayMessageType;
import ch.bfh.abcm.rems.gateway.GatewayMessage;
import ch.bfh.abcm.rems.sensors.tinkerforge.TFSensorType;
import ch.bfh.abcm.rems.tinkerforge.TFNodeAverageMessage;

public class SystemOkaySensorValidationJob extends AbstractValidationTest {

    @Test
    public void testEffectiveValueAndSystemOkayTemperature() throws InterruptedException {
        insertCorrectTempLuxHumSensorData(5);
        insertCorrectNodeAverages(5);
        new SensorValidationJob(HOST_IP_TEMPERATURE).now();
        Thread.sleep(WAIT_FOR_RECEIVING);
        Assert.assertNull(receiverimplemntation.getGatewayMessage());
        Assert.assertNull(receiverimplemntation.getUpdateNodeConfigMessage());
        Assert.assertNull(receiverimplemntation.getUpdateUserConfigMessage());
        Assert.assertNotNull(receiverimplemntation.getTfNodeAverageMessage());
        TFNodeAverageMessage averageMessage = receiverimplemntation.getTfNodeAverageMessage();
        Assert.assertEquals(averageMessage.getSensorType(), TFSensorType.TEMPERATURE);
        Assert.assertEquals(averageMessage.getMeasurementIP(), HOST_IP_TEMPERATURE);
    }
    
    @Test
    public void testEffectiveValueAndSystemOkayAmbient() throws InterruptedException {
        insertCorrectTempLuxHumSensorData(5);
        insertCorrectNodeAverages(5);
        new SensorValidationJob(HOST_IP_AMBIENT).now();
        Thread.sleep(WAIT_FOR_RECEIVING);
        Assert.assertNull(receiverimplemntation.getGatewayMessage());
        Assert.assertNull(receiverimplemntation.getUpdateNodeConfigMessage());
        Assert.assertNull(receiverimplemntation.getUpdateUserConfigMessage());
        TFNodeAverageMessage averageMessage = receiverimplemntation.getTfNodeAverageMessage();
        Assert.assertEquals(averageMessage.getSensorType(), TFSensorType.AMBIENT);
        Assert.assertEquals(averageMessage.getMeasurementIP(), HOST_IP_AMBIENT);
    }
    
    @Test
    public void testEffectiveValueAndSystemOkayHumidity() throws InterruptedException {
        insertCorrectTempLuxHumSensorData(5);
        insertCorrectNodeAverages(5);
        new SensorValidationJob(HOST_IP_HUMIDITY).now();
        Thread.sleep(WAIT_FOR_RECEIVING);
        Assert.assertNull(receiverimplemntation.getGatewayMessage());
        Assert.assertNull(receiverimplemntation.getUpdateNodeConfigMessage());
        Assert.assertNull(receiverimplemntation.getUpdateUserConfigMessage());
        TFNodeAverageMessage averageMessage = receiverimplemntation.getTfNodeAverageMessage();
        Assert.assertEquals(averageMessage.getSensorType(), TFSensorType.HUMIDITY);
        Assert.assertEquals(averageMessage.getMeasurementIP(), HOST_IP_HUMIDITY);
    }
}